//
//  AppMain.m
//  clublbiza
//
//  Created by WANG TOM on 7/28/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AppMain.h"
static AppMain *_shareInstance = nil;
@implementation AppMain
@synthesize currentSelectedMenuTabIndex;
@synthesize currentSelectedMenuVersionId;
@synthesize cacheMenuItemListData;
+ (AppMain *)shareInstance
{
    @synchronized(self){
        if(_shareInstance == nil)
        {
            _shareInstance = [[self alloc] init];
        }
        return _shareInstance;
    }
}
- (id)init {
	if (self = [super init]) {
		self.currentSelectedMenuTabIndex = -1;
        self.currentSelectedMenuVersionId = 0;
	}
	return self;
}
-(void) dealloc {
    [self.cacheMenuItemListData release];
    [super dealloc];
}
+(NSString *)resourceFolderPath
{
    NSArray *cache = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);     
    NSString *cachePath = [cache objectAtIndex:0] ;
    
    NSString *resourceDirPath = [cachePath stringByAppendingFormat:@"/resource"];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir;
    if ([fileManager fileExistsAtPath:resourceDirPath isDirectory:&isDir] && isDir) {
        
    }else{
        [fileManager createDirectoryAtPath:resourceDirPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    return resourceDirPath;
}
-(NSString *)getGateWayURL:(Boolean)onlyIndex
{
   // http://localhost/clublbiza_php/api.php?
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *defaultKey = @"GATE_WAY_URL";
    NSString *url = [userDefaults objectForKey:defaultKey];
    if (url == nil) {
        url = @"http://localhost/clublbiza_php";
        //url =  @"http://ipadapp.ibiza-shanghai.com";
        
        
    }
    if ( !onlyIndex ){
        url = [url stringByAppendingString:@"/api.php?"];
    }
    return url;
}
-(void)setGateWayURL:(NSString *)inputUrl
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *defaultKey = @"GATE_WAY_URL"; 
    [userDefaults setObject:inputUrl forKey:defaultKey];
}
+(NSArray*) getTabBarMenuTable
{
    return [NSArray arrayWithObjects:@"BEVERAGE",@"FOOD",@"IBIZA TV",@"EVENTS", @"ADVERTISEMENT", nil];
}
@end
